//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
// var $com;
// var MyComponent = {
//   data() { return { 
//     gz_list_gq: [
//       {
//         id: 0,
//         name: '不处理',
//       },
//       {
//         id: 1,
//         name: '自动核销',
//       },
//       {
//         id: 2,
//         name: '自动取消',
//       },
//     ],
//     gz_list_gq_index: 0,
//     autoEnd1: 0,
//     autoEnd2: 0,
//     autoEnd3: 0,
//     serviceShargeDiscount: 0,
//     isAutoEnd: ''
//    } },
//   created() {
//     $com = this;
//   },
//   methods: {
//     gz_list_gq_cl(v) {
//       this.gz_list_gq_index = v;
//     },
//   },
//   //创建自定义组件模板
//   template: `
//   <div class="VerificaonRules">
//     过期操作：
//     <el-button-group>
//       <el-button :class="gz_list_gq_index == ii ? 'hover' : ''"
//         v-for="(i, ii) in gz_list_gq" :key="ii" @click="gz_list_gq_cl(i.id)" round
//         size="mini">{{ i.name }}</el-button>
//     </el-button-group>
//     <div class="gz_maTop10" v-if="gz_list_gq_index == 1">
//       <el-input class="inputWid90" v-model="autoEnd1" size="mini" />天后自动核销
//     </div>
//     <div class="gz_maTop10" v-else-if="gz_list_gq_index == 2">
//       <el-input class="inputWid90" v-model="autoEnd2" size="mini" />天后自动取消，手续费
//       <el-input class="inputWid90" v-model="serviceShargeDiscount" size="mini" />%
//       <div>
//         <el-checkbox v-model="isAutoEnd">
//           已取票/部分取票订单不自动取消</el-checkbox>
//       </div>
//     </div>
//   </div>
//   `
// };
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    // 循环表单并返回数据
    getFormOption(field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    // 循环表格返回数据
    getColumnsOption(field) {
      let option;
      this.columns.forEach(item => {
        if (item.field == field) {
          option = item;
        }
      })
      return option;
    },
    onInit() {
      // label宽度
      this.boxOptions.labelWidth = 120
      // 弹框宽度
      this.boxOptions.width = 800
      // 开启单选
      //;
      // 内容超出后自动换行
      this.textInline = true;
      // 不显示多选框
      //;
      // 显示序号
      //;
      // 循环表单
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          let field = item.field
          if (field != "rulesName" && field != "expireOperation" && field != "playDate") {
            item.hidden = true
          }
        })
      })
      // 过期操作字段
      let expireOperation = this.getFormOption("expireOperation")//过期操作 1自动核销 2 自动取消 3 不处理
      let playExceedNum = this.getFormOption("playExceedNum")//过期操作 1自动核销 2 自动取消 3 不处理
      // 游玩日期字段
      let playDate = this.getFormOption("playDate")//游玩日期 1固定时间段 2游玩日期前后几天
      let timeContainer = this.getFormOption("timeContainer")//游玩固定起止时间
      let fewDaysAgo = this.getFormOption("fewDaysAgo")//游玩日期前几天
      let fewDaysLater = this.getFormOption("fewDaysLater")//游玩日期后几天
      // 修改title
      this.$set(playDate, "title", "游玩日期")
      this.$set(expireOperation, "title", "过期操作")
      expireOperation.onChange = (val, item) => {
        if (val != 3) {
          playExceedNum.hidden = false
          this.editFormFields.playExceedNum = 0
        } else {
          playExceedNum.hidden = true
          this.editFormFields.playExceedNum = 0
        }
      }
      // 游玩日期 playDate 绑定change事件
      playDate.onChange = (val, item) => {
        // console.log(val,"val")
        if (val == "1") {
          this.editFormFields.fewDaysAgo = ""
          this.editFormFields.fewDaysLater = ""
          this.editFormFields.timeContainer = ""
          this.$set(fewDaysAgo, "hidden", true)
          this.$set(fewDaysLater, "hidden", true)
          this.$set(timeContainer, "hidden", false)
        } else if (val == "2") {
          this.editFormFields.timeContainer = ""
          this.$set(timeContainer, "hidden", true)
          this.$set(fewDaysAgo, "hidden", false)
          this.$set(fewDaysLater, "hidden", false)
        } else if (val == "3") {
          // this.editFormFields.timeContainer = ""
          this.editFormFields.fewDaysAgo = ""
          this.editFormFields.fewDaysLater = ""
          this.editFormFields.timeContainer = ""
          this.$set(timeContainer, "hidden", true)
          this.$set(fewDaysAgo, "hidden", true)
          this.$set(fewDaysLater, "hidden", true)
        }
      }

    },
    rowClick({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    modelOpenAfter(row) {
      // 过期操作字段
      let expireOperation = this.getFormOption("expireOperation")//过期操作 1自动核销 2 自动取消 3 不处理
      // 游玩日期字段
      let playDate = this.getFormOption("playDate")//游玩日期 1固定时间段 2游玩日期前后几天
      let timeContainer = this.getFormOption("timeContainer")//游玩固定起止时间
      let fewDaysAgo = this.getFormOption("fewDaysAgo")//游玩日期前几天
      let fewDaysLater = this.getFormOption("fewDaysLater")//游玩日期后几天
      let playExceedNum = this.getFormOption("playExceedNum")//游玩日期后几天

      if (this.currentAction == "Add") {
        // this.editFormFields.expireOperation = expireOperation.data[0].key
        this.$set(fewDaysAgo, "hidden", true)
        this.$set(playExceedNum, "hidden", true)
        this.editFormFields.playExceedNum = 0

        this.$set(fewDaysLater, "hidden", true)
        this.$set(timeContainer, "hidden", true)
        this.editFormFields.expireOperation = "3"
        this.editFormFields.playDate = ""
        this.editFormFields.fewDaysAgo = ""
        this.editFormFields.fewDaysLater = ""
        this.editFormFields.timeContainer = ""
      } else if (this.currentAction == "update") {
        if (row.playDate == "1") {
          console.log("固定时间段");
          this.editFormFields.timeContainer = [row.playStartDate, row.playEndDate]
          this.$set(timeContainer, "hidden", false)
          this.$set(fewDaysAgo, "hidden", true)
          this.$set(fewDaysLater, "hidden", true)
          this.editFormFields.fewDaysAgo = ""
          this.editFormFields.fewDaysLater = ""
        } else if (row.playDate == "2") {
          console.log("游玩日期前后几天");
          this.$set(timeContainer, "hidden", true)
          this.$set(fewDaysAgo, "hidden", false)
          this.$set(fewDaysLater, "hidden", false)
          this.editFormFields.timeContainer = ""
        } else {
          this.editFormFields.fewDaysAgo = ""
          this.editFormFields.fewDaysLater = ""
          this.editFormFields.timeContainer = ""
          this.$set(fewDaysAgo, "hidden", true)
          this.$set(fewDaysLater, "hidden", true)
          this.$set(timeContainer, "hidden", true)
        }

      }
    },
    addBefore(formData) { //新建保存前formData为对象，包括明细表
      return this.veriFromTable(formData)
    },
    updateBefore(formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
      return this.veriFromTable(formData)
    },
    // 保存前编辑 
    veriFromTable(formData) {
      console.log("sss", formData);
      let playDate = this.editFormFields.playDate
      if (playDate == 3) {
        formData.mainData.fewDaysAgo = ''
        formData.mainData.fewDaysLater = ''
        formData.mainData.playStartDate = ''
        formData.mainData.playEndDate = ''
      } else if (playDate == 2) {
        formData.mainData.playStartDate = ''
        formData.mainData.playEndDate = ''
      } else {
        formData.mainData.fewDaysAgo = ''
        formData.mainData.fewDaysLater = ''
        let timeContainer = formData.mainData.timeContainer.split(",")
        if (timeContainer.length > 0 && timeContainer[0] != "") {
          formData.mainData.playStartDate = timeContainer[0]
          formData.mainData.playEndDate = timeContainer[1]
        }
      }
      return true
    },
    delBeforeDataAsync(ids, rows) {
      let obj = {
        url: '/api/distriProducts/getPageData',
        params: {
          order: "desc",
          page: 1,
          rows: 30,
          sort: "createDate",
          wheres: `[{\"name\":\"verificationrulesid\",\"value\":\"${ids.join()}\",\"displayType\":\"checkbox\"}]`
        }
      }
      return obj
    }
  }
};
export default extension;